<template>
  <div class="app-container">

    

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-select v-model="queryParams.projectName" filterable allow-create default-first-option placeholder="供应商名称">
          <el-option v-for="item in wuxia" :key="item.value" :label="item.projectName" :value="item.projectName">
          </el-option>
        </el-select>
      </el-form-item>


    <el-form-item label="构建类型" prop="compomentType">
        <el-select v-model="queryParams.compomentType" filterable allow-create default-first-option placeholder="供应商名称">
          <el-option v-for="item in goujianType" :key="item.value" :label="item.compomentType" :value="item.compomentType">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="构件编号" prop="compomentNo">
        <el-input
          v-model="queryParams.compomentNo"
          placeholder="请输入构件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="构件名称" prop="compomentName">
        <el-input
          v-model="queryParams.compomentName"
          placeholder="请输入构件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="楼栋" prop="build">
        <el-select v-model="queryParams.build" filterable allow-create default-first-option placeholder="供应商名称">
          <el-option v-for="item in loudong" :key="item.value" :label="item.build" :value="item.build">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工艺流程名称" prop="processName">
        <el-select v-model="queryParams.processName" filterable allow-create default-first-option placeholder="供应商名称">
          <el-option v-for="item in gongyi" :key="item.value" :label="item.processName" :value="item.processName">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否导入BOM" prop="isImportBOM">
        <el-select v-model="queryParams.isImportBOM" filterable allow-create default-first-option placeholder="供应商名称">
          <el-option v-for="item in wuxia" :key="item.value" :label="item.isImportBOM" :value="item.isImportBOM">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:info:add']"
        >新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['project:info:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['project:info:remove']"
        >批量删除</el-button>
      </el-col>
      <el-dropdown>
  <el-button type="primary">
    零件导入<i class="el-icon-arrow-down el-icon--right"></i>
  </el-button>
  <el-dropdown-menu slot="dropdown">
    <el-dropdown-item @click.native="clickGeneratePicture">零件模板下载</el-dropdown-item>
  </el-dropdown-menu>
</el-dropdown>

      <el-dropdown>
        
  <el-button type="primary">
    构件BOM<i class="el-icon-arrow-down el-icon--right"></i>
  </el-button>
  <el-dropdown-menu slot="dropdown">
    <el-dropdown-item @click.native="down">BOM导入</el-dropdown-item>
    <el-dropdown-item>BOM模板下载</el-dropdown-item>
  </el-dropdown-menu>
</el-dropdown>

<el-button type="primary" @click="nnnn">
    12345
  </el-button>

      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:info:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="构件编号" align="center" prop="compomentNo"></el-table-column>
      <el-table-column label="构件名称" align="center" prop="compomentName" />
      <el-table-column label="项目名称" align="center" prop="projectName"/>
      <el-table-column label="构建数量" align="center" prop="count" />
      <el-table-column label="工艺流程名称" align="center" prop="processName" />
      <el-table-column label="工艺路径" align="center" prop="technologicalProcess" />
      <el-table-column label="楼栋" align="center" prop="build" />
      <el-table-column label="产出量(t)" align="center" prop="yieldCount" />
      <el-table-column label="构件类型" align="center" prop="compomentType" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['project:info:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['project:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleXg(scope.row)"
          >修改产线
        </el-button>
          
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改构件维护对话框 -->
    <el-dialog :title="title"  :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目名称" prop="projectName">
        <el-select v-model="queryParams.projectName" filterable allow-create default-first-option placeholder="请选择">
          <el-option v-for="item in wuxia1" :key="item.value" :label="item.projectName" :value="item.projectName">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="构建类型" prop="compomentType">
        <el-select v-model="queryParams.compomentType" filterable allow-create default-first-option placeholder="请选择">
          <el-option v-for="item in goujianType1" :key="item.value" :label="item.compomentType" :value="item.compomentType">
          </el-option>
        </el-select>
      </el-form-item>
        <el-form-item label="构件名称" prop="compomentName">
          <el-input v-model="form.compomentName" placeholder="请选择" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>







    <!-- 修改产线对话框 -->
    <el-dialog :title="title1"  :visible.sync="open1" width="800px" append-to-body>
      <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="工艺流程名称" align="center" prop="processName">
        <template slot-scope="scope">
          <el-select v-model="queryParams.processName" filterable allow-create default-first-option placeholder="工艺流程名称">
          <el-option v-for="item in gongyi" :key="item.value" :label="item.processName" :value="item.processName">
          </el-option>
        </el-select>
      </template>
      </el-table-column>
      <el-table-column label="工艺路径" align="center" prop="technologicalProcess" >
        <template slot-scope="scope">
          <el-select v-model="queryParams.technologicalProcess" filterable allow-create default-first-option placeholder="工艺流程名称">
          <el-option v-for="item in gongyiLu" :key="item.value" :label="item.technologicalProcess" :value="item.technologicalProcess">
          </el-option>
        </el-select>
      </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">确 定</el-button>
        <el-button @click="cancel1">取 消</el-button>
      </div>
    </el-dialog>



    <!-- 导入bom对话框 -->
    <el-dialog :title="title2"  :visible.sync="open2" width="800px" append-to-body>
      <el-form :model="queryParams" ref="form" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-select v-model="queryParams.projectName" filterable allow-create default-first-option placeholder="请选择">
          <el-option v-for="item in wuxia" :key="item.value" :label="item.projectName" :value="item.projectName">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="楼栋" prop="build">
        <el-select v-model="queryParams.build" filterable allow-create default-first-option placeholder="请选择">
          <el-option v-for="item in loudong" :key="item.value" :label="item.build" :value="item.build">
          </el-option>
        </el-select>
      </el-form-item>

      <div style="margin-left:400px">
        <el-upload
  class="upload-demo"
  drag
  action="https://jsonplaceholder.typicode.com/posts/"
  multiple>
  <i class="el-icon-upload"></i>
  <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
  <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>
</el-upload>
      </div>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, Floor,dateInfo } from "@/api/project/info";

export default {
  name: "Info",
  data() {
    return {
      wuxia:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      form:{},
      // 构件维护表格数据
      infoList: [],
      goujianType: [],
      goujianType1: [],
      loudong: [],
      gongyi: [],
      gongyiLu: [],
      wuxia1: [],
      infoListXg:[],
      // 弹出层标题
      title: "",
      title1: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      lo:'',
      po:'',

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        compomentNo: null,
        compomentType: null,
        compomentName: null,
        projectName:null,
        build:null,
        processName:null,
        isImportBOM:null,
        technologicalProcess:null,
        createBy:null,
        createTime: null,
        projectNo:null,
        remark:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectNo:[
        { required: true, message: "项目编号不能为空", trigger: "change" },
        ],
        compomentName:[
        { required: true, message: "构件名称不能为空", trigger: "change" },
        ],
        projectName:[
        { required: true, message: "项目名称不能为空", trigger: "change" },
        ]
      }
    };
  },
  created() {
    listInfo(this.queryParams).then(res => {
      for(let i = 0;i<res.rows.length;i++){
          this.wuxia = res.rows[i].projectName
          this.wuxia = res.rows
          this.goujianType = res.rows[i].compomentType
          this.goujianType = res.rows
          this.goujianType1 = res.rows[i].compomentType
          this.goujianType1 = res.rows
          this.loudong = res.rows[i].floor
          this.loudong = res.rows
          this.gongyi = res.rows[i].processName
          this.gongyi = res.rows
          this.gongyiLu = res.rows[i].technologicalProcess
          this.gongyiLu = res.rows
          this.wuxia1 = res.rows[i].processName
          this.wuxia1 = res.rows
        }
    })
    this.getList();
  },
  methods: {
    down(){
      console.log("bom下载");
      this.open2 = true;
    },
    clickGeneratePicture(){
        console.log(2134231)
    },
    nnnn(lo){
      console.log(123213,this.lo)
      Floor(this.lo).then(res=>{
        console.log(res,"lllll")
      })
      this.$router.push({path:"/info/BuildUphold",query:{lo:this.lo,po:this.po}})
    },
    enterIn(row, event, column){
      console.log(123)
    },
    handleClick() {
        alert('button click');
      },
    /** 查询构件维护列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
        console.log(response.rows[0].compomentNo)
        this.lo = response.rows[0].compomentNo
        this.po = response.rows[0].projectNo
        console.log(this.po)
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    dianji(){
console.log(123132131)
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectNo: null,
        compomentNo: null,
        compomentType: null,
        build:null,
        compomentName: null,
        specifications: null,
        texture: null,
        length: null,
        surfaceArea: null,
        grossWeight: null,
        netWeight: null,
        processNo: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        comment: null,
        processName:null,
        isImportBOM:null,
        technologicalProcess:null,
      };
      this.resetForm("form");
    },
    
    /** 搜索按钮操作 */
    handleQuery() {
      
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加构件维护";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改构件维护";
      });
    },
    // 修改产线
    handleXg(row){
      this.open1 = true;
      // dateInfo(this.queryParams).then(res=>{
        console.log(res)
        this.title1 = "修改产线";
        this.listInfo()
      // })
      
      
    },
    submitForm1(){
      dateInfo(this.queryParams).then(res=>{
        console.log(res)
      })
      this.$modal.msgSuccess("修改成功");
      this.open1 = false;
      this.getList();
    },
    cancel1(){
      this.open1 = false
    },
    submitForm2(){
      this.open2 = false;
    },
    cancel2(){
      this.open2 = false
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除构件维护编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
  .el-dropdown {
    vertical-align: top;
  }
  .el-dropdown + .el-dropdown {
    margin-left: 15px;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
</style>
